#pragma once
#include<iostream>
#include<pthread.h>

namespace MutexModel{
    class Mutex{
        public:
        Mutex(){
            pthread_mutex_init(&lock,nullptr);
        }
        void Lock(){
            pthread_mutex_lock(&lock);
        }
        void UnLock(){
            pthread_mutex_unlock(&lock);
        }
        pthread_mutex_t* Get(){
            return &lock;
        }
        ~Mutex(){
            pthread_mutex_destroy(&lock);
        }
        private:
        pthread_mutex_t lock;
    };

    //自动上锁解锁
    class Guard{
        public:
        Guard(Mutex* _lock){
            lock = _lock;
            lock->Lock();
        }
        ~Guard(){
            lock->UnLock();
        }
        private:
        Mutex* lock;
    };

}
